package com.base.controller;

import com.base.po.param.NetState;
import com.base.po.voip.IncomeTable;
import com.base.po.voip.UserBankSetting;
import com.base.service.IncomeTableService;
import com.base.service.UserBankSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Controller
@RequestMapping("admin")
public class UserBankSettingController {

    @Autowired
    UserBankSettingService userBankSettingService;
    @Autowired
    IncomeTableService incomeTableService;

    // 账户配置主页
    @RequestMapping(value = "/insertBankNews",produces="application/json;charset=utf-8")
    public @ResponseBody
    String index(HttpServletRequest request, String adminid, String aliaccount, String bankname, String bankno, String bankrealname, String name, String mobile) {
        UserBankSetting userBankSetting1 = userBankSettingService.selectByUsers(adminid);
        if (userBankSetting1 != null) {
            return "已经配置过了";
        }
        UserBankSetting userBankSetting = new UserBankSetting();
        userBankSetting.setAliaccount(aliaccount);
        userBankSetting.setBankname(bankname);
        userBankSetting.setBankno(bankno);
        userBankSetting.setBankrealname(bankrealname);
        userBankSetting.setMobile(mobile);
        userBankSetting.setDatastatus("1");
        userBankSetting.setCreatetime(new Date());
        userBankSetting.setUserid(adminid);
        int code = userBankSettingService.insertSelective(userBankSetting);

        if (code > 0) {
            return "配置用户信息完成";
        }

        return "新增失败";
    }


    // 账户配置主页
    @RequestMapping("/finduserpay")
    public @ResponseBody
    NetState finduserpay(HttpServletRequest request, Integer id) {
        NetState netState = new NetState();
        IncomeTable incomeTable = incomeTableService.selectByPrimaryKey(id);
        if (incomeTable == null) {
            netState.setErrorCode(NetState.FEAILED);
            netState.setData("未查询到该提现记录");
            return netState;
        }
       String userid=  incomeTable.getShopid();
        UserBankSetting userBankSetting=userBankSettingService.selectByUsers(userid);
        if (userBankSetting!=null){
            netState.setErrorCode(NetState.SUCCESS_CONN);
            netState.setData("已查询");
            netState.setJson(userBankSetting);
            return netState;
        }
        return netState;
    }

    // 账户配置主页
    @RequestMapping("/deleteUsersBankNews")
    public @ResponseBody
    NetState deleteUsersBankNews(HttpServletRequest request, String id) {
        NetState netState = new NetState();
        UserBankSetting userBankSetting=userBankSettingService.selectByUsers(id);
        if (userBankSetting!=null){
            userBankSettingService.deleteByPrimaryKey(userBankSetting.getId());
            netState.setData("已清除收款信息");
            netState.setErrorCode(NetState.SUCCESS_CONN);
        }else{
            netState.setData("该代理商没有提现记录");
            netState.setErrorCode(NetState.SUCCESS_CONN);
        }
        return netState;
    }

}
